<?php
declare (strict_types = 1);

namespace app\listener\backend;

use app\service\logic\common\home\NoticeService;
use Exception;
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
use think\facade\Log;

class WebsiteNoticeListener
{
    /**
     * @param $argc
     * @return mixed
     */
    public function handle($argc)
    {
        try {
            $inserts = [];
            if (empty($argc['admin_ids'])) {
                $argc['data']['admin_id'] = 0;
                $inserts[] = $argc['data'];
            } else {
                $adminIds = explode(',', $argc['admin_ids']);
                foreach ($adminIds as $adminId) {
                    foreach ($argc['data'] as $item) {
                        $item['admin_id'] = $adminId;
                        $inserts[] = $item;
                    }
                }
            }
            return invoke(NoticeService::class)->create($inserts);
        } catch (Exception $e) {
            Log::debug('WebsiteNoticeListenerException: message=' . $e->getMessage() . ', argc=' . var_export($argc, true));
            return true;
        }
    }
}
